﻿using DG.Tweening;
using UnityEngine;

public class CriticalNumberTween : MonoBehaviour, ITween
{
    private WorldNumber _worldNumber;

    private void Awake()
    {
        _worldNumber = GetComponent<WorldNumber>();
    }

    public void Play()
    {
        DOTween.Sequence()
            .Append(transform.DOScale(Vector3.one, 0.35f).From(Vector3.one * 4.5f))
            .Join(_worldNumber.TextMesh.DOFade(1f, 0.1f).From(0f))
            .AppendInterval(0.4f)
            .Append(_worldNumber.TextMesh.DOFade(0f, 0.15f))
            .OnComplete(() => _worldNumber.Stop());
    }

    public void Stop()
    {
        var color = _worldNumber.TextMesh.color;
        color.a = 0f;
        _worldNumber.TextMesh.color = color;
    }
}